home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / Demo.java < prev    next >
Text File  |  1998-08-21  |  4KB  |  206 lines

  1. package symantec.itools.demo;
  2.  
  3.  
  4. import java.applet.Applet;
  5. import java.awt.Component;
  6. import java.awt.FlowLayout;
  7. import java.awt.Font;
  8. import java.awt.Graphics;
  9. import java.awt.LayoutManager;
  10. import symantec.itools.awt.util.Util;
  11.  
  12.  
  13. /**
  14.  * A demonstration Applet class.
  15.  *
  16.  * @version 1.0, Nov 26, 1996
  17.  *
  18.  * @author    Symantec
  19.  */
  20. public abstract class Demo
  21.     extends Applet
  22. {
  23.     /**
  24.      * Frame title.
  25.      */
  26.     protected String       title;
  27.     /**
  28.      * True if this class is invoked as an Applet.
  29.      */
  30.     protected boolean      isApplet;
  31.     /**
  32.      * This program's frame.
  33.      */
  34.     protected DemoFrame    frame;
  35.     /**
  36.      * The frame horizontal position, in pixels.
  37.      */
  38.     protected int          xPos;
  39.     /**
  40.      * The frame vertical position, in pixels.
  41.      */
  42.     protected int          yPos;
  43.     /**
  44.      * The frame width, in pixels.
  45.      */
  46.     protected int          width;
  47.     /**
  48.      * The frame height, in pixels.
  49.      */
  50.     protected int          height;
  51.  
  52.     /**
  53.      * Constucts the Demo object.
  54.      * @param s the frame title
  55.      * @param x the frame horizontal position, in pixels
  56.      * @param y the frame vertical position, in pixels
  57.      * @param w the frame width, in pixels
  58.      * @param h the frame height, in pixels
  59.      */
  60.     public Demo(String s, int x, int y, int w, int h)
  61.     {
  62.         title  = s;
  63.         xPos   = x;
  64.         yPos   = y;
  65.         width  = w;
  66.         height = h;
  67.     }
  68.  
  69.     /**
  70.      * Called by the Applet viewer to initialize this applet.
  71.      * @see java.applet.Applet#init
  72.      */
  73.     public void init()
  74.     {
  75.         isApplet = true;
  76.         setup();
  77.         frame.show();
  78.     }
  79.  
  80.     /**
  81.      * Called to initialize this object if it is not an applet.
  82.      */
  83.     protected void driver()
  84.     {
  85.         isApplet = false;
  86.         setup();
  87.         frame.show();
  88.     }
  89.  
  90.     /**
  91.      * Shared setup code.
  92.      */
  93.     protected void setup()
  94.     {
  95.         frame = new DemoFrame(this, title);
  96.         frame.reshape(xPos, yPos, width, height);
  97.         frame.setLayout(new FlowLayout());
  98.     }
  99.  
  100.     /**
  101.      * Called to end this demo.
  102.      */
  103.     public void endDemo()
  104.     {
  105.         if(isApplet)
  106.         {
  107.             stop();
  108.         }
  109.         else
  110.         {
  111.             System.exit(0);
  112.         }
  113.     }
  114.  
  115.     /**
  116.      * Hides and disposes the frame.
  117.      */
  118.     public void cleanup()
  119.     {
  120.            frame.hide();
  121.         frame.dispose();
  122.     }
  123.  
  124.     /**
  125.      * Hides and disposes the frame, then exits.
  126.      */
  127.     public void doExit()
  128.     {
  129.         cleanup();
  130.         endDemo();
  131.     }
  132.  
  133.     /**
  134.      * Handles demo help requests.
  135.      */
  136.     public void doHelp()
  137.     {
  138.     }
  139.  
  140.     /**
  141.      * Handles demo "About..." requests.
  142.      */
  143.     public void doAbout()
  144.     {
  145.     }
  146.  
  147.     /**
  148.      * Reinitializes the demo.
  149.      */
  150.     public void doRestart()
  151.     {
  152.         cleanup();
  153.         setup();
  154.     }
  155.  
  156.     public Component add(Component c)
  157.     {
  158.         return (frame.add(c));
  159.     }
  160.  
  161.     public synchronized Component add(Component c, int i)
  162.     {
  163.         return (frame.add(c, i));
  164.     }
  165.  
  166.     public synchronized Component add(String s, Component c)
  167.     {
  168.         return (frame.add(s, c));
  169.     }
  170.  
  171.     public void setLayout(LayoutManager manager)
  172.     {
  173.         if(frame != null)
  174.         {
  175.             frame.setLayout(manager);
  176.         }
  177.     }
  178.  
  179.     public Graphics getGraphics()
  180.     {
  181.         return frame.getGraphics();
  182.     }
  183.  
  184.     /**
  185.      * Gets the font to use for this Demo.
  186.      * @return the font
  187.      */
  188.     public Font getFont()
  189.     {
  190.         Font font;
  191.  
  192.         if(frame != null)
  193.         {
  194.             font = frame.getFont();
  195.  
  196.             font = (font == null) ? Util.getDefaultFont() : font;
  197.         }
  198.         else
  199.         {
  200.             font = Util.getDefaultFont();
  201.         }
  202.  
  203.         return font;
  204.     }
  205. }
  206.